<?php

class User_Controller_Browse_Login extends Nuo_Controller
{
	function execute($request)
	{
		$form = Nuo::getObject('user/login', 'form');

		if ($request -> getMethod() == 'POST' && $form -> isValid($_POST))
		{
			$user = Nuo::getApi('user') -> login($_POST);

			if (is_object($user))
			{
				$user -> login();
				$uri = Nuo::getUrl('/');
				Nuo::redirect($uri);
			}
			else
			{
				switch($user)
				{
					case -1 :
						$form -> setNotice('Account does not exists!');
						break;
					case -2 :
						$form -> setNotice('Password Not match!');
						break;
					case 1 :
						$form -> setNotice('Login succesful!');
						break;
					default :
						$form -> setNotice('Login failed!');
				}
			}
		}
		return   $form->__toString();
	}

}
